package com.eric.server.logic.packet;

import com.eric.server.packet.Packet;
import com.eric.server.packet.PacketType;
import io.netty.buffer.ByteBuf;

import java.nio.charset.Charset;

/**
 * Created by eric on 2017/11/16.
 */
public class NoticePacket extends Packet {
    public String msg ; // 通知消息

    public NoticePacket(String msg){
        this.msg = msg;
    }

    public NoticePacket(){}

    public void writePacketMsg(ByteBuf buf) {
        writeUTF8(buf,msg);
    }

    public void readFromBuff(ByteBuf buf) {
        msg = readUTF8(buf);
    }

    public PacketType getPacketType() {
        return PacketType.NoticeClient;
    }

    public void execPacket() {

    }

    @Override
    protected int getBodyLength() {
        int length = 0 ;
        byte[] bb = msg.getBytes(Charset.forName("utf-8"));
        length += bb.length +4;

        return length;
    }

    public static NoticePacket obtain(String msg){
        return  new NoticePacket(msg);
    }
}
